/**
 * 
 */
package com.lion.jacoco.web.home.module.screen;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.lion.jacoco.biz.JsonUtil;
import com.lion.jacoco.manager.AppManager;

/**
 * RemoveApp.java. 2011-12-7下午5:41:39 @author LionBule.
 */
public class RemoveApp {
    @Autowired
    private HttpServletResponse response;
    @Autowired
    private AppManager          appManager;

    public void execute(@Param("pid") final int pid, Context context) throws Exception {
        response.setContentType("text/plain; charset=UTF-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
            if (pid <= 0) {
                out.print(JsonUtil.getFailedResult("parameter value is invalid."));
            } else {
                String result = appManager.deleteAppById(pid);
                out.print(JsonUtil.getSuccessfulResult(result));
                return;
            }
        } catch (Exception e) {
            out.print(JsonUtil.getFailedResult("System exception."));
        } finally {
            out.flush();
        }

    }

}
